﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FacebookWrapper;
using FacebookWrapper.ObjectModel;

namespace Ex3
{
    public partial class LoginForm : Form
    {
        #region DataMembers

        public User m_LoggedInUser { get; private set; }

        #endregion

        public LoginForm()
        {
            this.InitializeComponent();
        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
           this.loginAndInit();
           this.Hide();
        }

        private void loginAndInit()
        {
            /// App: Demo
            /// Owner: design.patterns
            /// User: design.patterns
            /// 
            /// use this AccessToken to connect to design.patterns user via :
            /// LoginResult result = FacebookService.Connect("CAATyiqZBEpU0BAK6GldJGFK36ZAw1ZCORZBUb6fpZAkQjz7UsPDupRJaZB3xG0ptGGLZAHhV4cPu26eUa6KU1jWVr5HCkGDaDdPS0hYqjKU5MbJUohI4vvZBhZC5st3BqmllQuZBUfgGWXaKUZBZBMIx86nSAZAwOGRro2e8VvPUU9dP3UgZDZD");

            /// Use the FacebookService.Login method to display the login form to any user who wish to use this application.
            /// You can then save the result.AccessToken for future auto-connect to this user:
            
            // this is instead of the 'user_checkins' permission, as desricbed here: http://developers.facebook.com/bugs/170251059758531
            LoginResult result = FacebookService.Login(
                "218825708268152",
                "user_about_me",
                "user_status",
                "user_photos",
                 "user_checkins", 
                 "friends_checkins",
                 "read_stream",
                 "friends_birthday",
                 "friends_relationships");
               
            if (string.IsNullOrEmpty(result.ErrorMessage))
            {
                this.m_LoggedInUser = result.LoggedInUser;
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(result.ErrorMessage);
            }
        }

        private void buttonExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
